#include "stdafx.h"
#include "BasicSkinRootView.h"
#include "BasicSkinWidget.h"

namespace BasicSkinView
{
	CBasicSkinRootView::CBasicSkinRootView()
		:m_pWidget(NULL)
	{
		ClearInvalidateRect();
	}

	CBasicSkinRootView::~CBasicSkinRootView()
	{
	}
	
	CBasicSkinWidget* CBasicSkinRootView::GetWidget()
	{
		return m_pWidget;
	}

	void CBasicSkinRootView::SetWidget(CBasicSkinWidget* pWidget)
	{
		m_pWidget = pWidget;
	}

	void CBasicSkinRootView::SchedulePaintInRect(const RECT& rc)
	{
		if(m_pWidget && m_pWidget->m_hWnd)
		{
			UnionRect(&m_rcInvalidate,&m_rcInvalidate,&rc);
			if(m_rcInvalidate.left < 0) m_rcInvalidate.left = 0;
			if(m_rcInvalidate.top < 0) m_rcInvalidate.top = 0;
			if(m_rcInvalidate.right > m_rcView.right) m_rcInvalidate.right = m_rcView.right;
			if(m_rcInvalidate.bottom > m_rcView.bottom) m_rcInvalidate.bottom = m_rcView.bottom;

			::InvalidateRect(m_pWidget->m_hWnd,&rc,FALSE);
		}
	}

	void CBasicSkinRootView::ClearInvalidateRect()
	{
		::SetRectEmpty(&m_rcInvalidate);
	}
}